package vue;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.TextArea;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import modele.PluginFinder;
import controleur.HelpEnControl;
import controleur.HelpFrControl;
import controleur.PluginEventControl;
import controleur.QuitControl;
import controleur.SaveControl;
import controleur.cleanerControl;
/**
 * create the principal window
 * @author morhib & yann
 *
 */
@SuppressWarnings("serial")
public class WindowEditor extends JFrame {

	private JPanel panelmenu;
	private JPanel paneltext;
	private JPanel panelimg;
	private TextArea text;

	private JMenuBar jmBar;

	private JMenu jmfile;
	private JMenuItem jmiclean;
	private JMenuItem jmisave;
	private JMenuItem jmiquit;

	private JMenu jmtools;

	private JMenu jmhelp;
	private JMenuItem jmilangfr;
	private JMenuItem jmilangen;
	
	private PluginFinder finder;
/**
 * constructor
 */
	public WindowEditor() {
		/** add the principal element in the window */
		super("Extendable Editor");
		
		ImageIcon picture = new ImageIcon("ressources/img-ext.png");
		JLabel lab = new JLabel(picture); 

		
		panelmenu = new JPanel();
		paneltext = new JPanel();
		panelimg = new JPanel();
		jmBar = new JMenuBar();
		text = new TextArea();

		/* adding panels */
		this.add(this.panelmenu,BorderLayout.NORTH);
		this.add(this.panelimg,BorderLayout.CENTER);
		this.add(this.paneltext,BorderLayout.SOUTH);
		
		
		
		this.panelimg.add(lab);
		this.paneltext.add(this.text);
		this.panelmenu.add(this.jmBar);

		jmfile = new JMenu("File");
		jmiclean = new JMenuItem("Clean window");
		jmisave = new JMenuItem("save your text");
		jmiquit = new JMenuItem("Quit");
		jmfile.add(jmiclean);
		jmfile.add(jmisave);
		jmfile.add(jmiquit);

		jmtools = new JMenu("Tools");

		jmhelp = new JMenu("Help");
		jmilangen = new JMenuItem("English version");
		jmilangfr = new JMenuItem("Frensh version");
		jmhelp.add(jmilangen);
		jmhelp.add(jmilangfr);

		jmBar.add(jmfile);
		jmBar.add(jmtools);
		jmBar.add(jmhelp);

		this.setJMenuBar(jmBar);

		/* set window */
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(new Dimension(750, 400));
		setResizable(false);
		setLocationRelativeTo(null);
		setVisible(true);

		/* create pluginfinder */
		File file = new File("bin/plugins");
		this.finder = new PluginFinder(file);
		PluginEventControl listener = new PluginEventControl(this);
		finder.addlistener(listener);
		
		
		SaveControl saveListener = new SaveControl(this);
		jmisave.addActionListener(saveListener);		
		
		cleanerControl cleanlistener = new cleanerControl(this);
		jmiclean.addActionListener(cleanlistener);
		
		
		QuitControl quitlistener = new QuitControl(this);
		jmiquit.addActionListener(quitlistener);
		
		HelpEnControl enlistener = new HelpEnControl();
		jmilangen.addActionListener(enlistener);
		
		HelpFrControl frlistener = new HelpFrControl();
		jmilangfr.addActionListener(frlistener);
		
		
		finder.start();
	}

	public TextArea getTextArea(){
		return this.text;
	}
	public JMenu getTools(){
		return this.jmtools;
	}
	
	
}
